package com.pi.reservaCita2.client;

//package com.pi.reservaCita.client;

import java.util.Date;

import org.apache.http.cookie.SetCookie;

import com.pi.reservaCita2.controler.*;
import com.sun.java.swing.plaf.windows.resources.windows;
import com.google.gwt.user.client.*;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.event.dom.client.*;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.i18n.client.DateTimeFormat.PredefinedFormat;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.*;
import com.google.gwt.user.datepicker.client.DateBox;
import com.google.gwt.user.datepicker.client.DatePicker;

public class ReservaCita2 implements EntryPoint {
	
	
	private HorizontalPanel mainPanel = new HorizontalPanel();
	private VerticalPanel downPanel = new VerticalPanel();
	private HorizontalPanel searchpanel = new HorizontalPanel();
	private TextBox Box = new TextBox();
	private Label lastUpdatedLabel = new Label();
	private FechBarHandler banner = new FechBarHandler();
	private CitasView citab = new CitasView(2.5, Unit.EM);
	public DatePicker calendar = new DatePicker();
	private Button link = new Button("hazme click");
	@Override
	public void onModuleLoad() {
		// TODO Auto-generated method stub
		// Create table for stock data.
		/*
		 * estableciendo cookies
		 * 
		 * */
		String esp="12";
		Cookies.setCookie("especialidad",esp);
		
		searchpanel.add(banner.getDateBoxebegin());
		searchpanel.add(banner.getDateBoxeend());
		searchpanel.add(banner.getSearch());
		searchpanel.add(banner.getTxt());
		// Assemble Add Stock panel.
		
		downPanel.add(Box);
		mainPanel.add(searchpanel);
		mainPanel.add(downPanel);
		mainPanel.add(lastUpdatedLabel);
		//citab.DrawTable(banner.getListadatosdb());
		//mainPanel.add(citab);
	    
		// TODO Associate the Main panel with the HTML host page.
		// TODO Move cursor focus to the input box.
		// Associate the Main panel with the HTML host page.
		RootPanel.get("mainMenu").add(mainPanel);
		
		// Move cursor focus to the input box.
		//loginbuttons.getnewSymbol().setFocus(true);

		// Listen for mouse events on the Add button.

		/*
		 * newSymbolTextBox.addKeyPressHandler(new KeyPressHandler() { public
		 * void onKeyPress(KeyPressEvent event) { if (event.getCharCode() ==
		 * KeyCodes.KEY_ENTER) {//??????? addStock(); } } });
		 */
		link.addClickHandler(new ClickHandler() {
		      public void onClick(ClickEvent event) {
		        //int removedIndex = stocks.indexOf(symbol);
		        //stocks.remove(removedIndex);        stocksFlexTable.removeRow(removedIndex + 1);
		      Window.Location.assign("/login");
		      }
		    });
		calendar.addValueChangeHandler(new ValueChangeHandler<Date>() {
			public void onValueChange(ValueChangeEvent event) {
				Date date = (Date) event.getValue();
				String dateString = DateTimeFormat.getMediumDateFormat()
						.format(date);
				
				Box.setText(dateString);
			}
		});

	}

	public void getObservable() {

		GetObservableAsync obs = GWT.create(Observable.class);
		if (obs == null) {
			obs = GWT.create(Observable.class);
		}
		AsyncCallback<Observable> callback = new AsyncCallback<Observable>() {

			@Override
			public void onFailure(Throwable caught) {
				// TODO Auto-generated method stub

			}

			@Override
			public void onSuccess(Observable result) {
				// TODO Auto-generated method stub

				setObservable(result);
			}
		};

		obs.getaObss("", callback);
		// return result;
	}

	public void setObservable(Observable var) {
		//model = var;

	};

	/**
	 * Add stock to FlexTable. Executed when the user clicks the addStockButton
	 * or presses enter in the newSymbolTextBox.
	 */

}